1468E - Four Segments - CodeForces Solution


greedy *800

Please click on ads to support us..

Python Code:

trials = int(input())
area = ''
for i in range(trials):
    segments = input()
    segments_list = segments.split()
    int_segments_list = []
    for j in segments_list:
        int_segments_list.append(int(j))
    int_segments_list.sort()
    if int_segments_list[0] == int_segments_list[1] == int_segments_list[2] == int_segments_list[3] or int_segments_list[0] == int_segments_list[1] == int_segments_list[2] or int_segments_list[1] == int_segments_list[2] == int_segments_list[3]:
        area += (str(int_segments_list[0] * int_segments_list[1]) + '\n')
    elif int_segments_list[0] == int_segments_list[1] and int_segments_list[2] == int_segments_list[3]:
        area += (str(int_segments_list[0] * int_segments_list[2]) + '\n')
    elif int_segments_list[0] == int_segments_list[1] or int_segments_list[1] == int_segments_list[2] or int_segments_list[2] == int_segments_list[3]:
        if int_segments_list[0] == int_segments_list[1]:
            area += (str(int_segments_list[0] * int_segments_list[2]) + '\n')
        elif int_segments_list[1] == int_segments_list[2]:
            area += (str(int_segments_list[0] * int_segments_list[1]) + '\n')
        elif int_segments_list[2] == int_segments_list[3]:
            area += (str(int_segments_list[0] * int_segments_list[2]) + '\n')
    else:
        area += (str(int_segments_list[0] * int_segments_list[2]) + '\n')
print(area)

C++ Code:

//Think twice code once :))
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
 #define pb push_back
 typedef long double ld;
 //typedef __int128 lll;
 signed main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 ll tt=1;cin>>tt;string pi = "3.141592653589793238462643383279";
 while(tt--){ll arr[4];cin>>arr[0]>>arr[1]>>arr[2]>>arr[3];
 sort(arr,arr+4);
 cout<<arr[0]*arr[2]<<'\n';







}
 return 0;
 }





































/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
//sometimes long long ko int krne par tle nhi aata(kaafi ajeeb :())
 // Binary search me r=n+1,l=0&&condition:l+1>r;
 
// for(int i=2;i<=N;i++){
  //  if(prime[i]==0){
    //v.pb(i);
    //for(int j=2*i;j<=N;j+=i){prime[j]++;}
    //}
 //}
 /*int smallestdivisor(int n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;
 
    // iterate from 3 to sqrt(n)
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
 
    return n;
}*/
/*ll binpow(ll a,ll b,ll m = LLONG_MAX){
    ll res = 1;
    while (b){
        if (b&1) res = (res*a)%m;
        a = (a*a)%m;
        b>>=1;
    }
    return res;
}*/
/*for(int i=0;i<n;i++){
  if(m[s[i]]==0){
 if(i1==-1){ a[i]+=i+(n-1-i)*(i)+n-1-i;a[i]++;i1=i;}
 else{
  a[i]+=i-i1-1+(n-1-i)*(i-i1-1)+n-1-i;a[i]++;i1=i;
 }
  }
}
for(int i=0;i<n;i++){
  ans-=a[i];
}*/
/////Favorites>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>............................................
/*ll n,k;cin>>n>>k;
 if(n%2==0){
  if(k%n)cout<<k%n<<'\n';
  else{cout<<n<<'\n';}
 }
 else{ll n1=n-1;n1/=2;ll a=(k-1)/n1;ll b=k%n;
  if(b==0){b=n;}b+=a;b%=n;if(b==0){b=n;}
  cout<<b<<'\n';
  
 }*/
 


Comments

Submit
0 Comments
More Questions

1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum